﻿using System;
using System.Linq;
using Adalbertus.BudgetPlanner.Domain;
using Adalbertus.BudgetPlanner.Domain.Repositories;
using NHibernate.Linq;

namespace Adalbertus.BudgetPlanner.Infrastructure.Repositories
{
    public class BudgetRepository : Repository<Budget>, IBudgetRepository
    {
        public BudgetRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        public Budget GetBudgetByDate(DateTime budgetDate)
        {
            return UnitOfWork.Session.Query<Budget>()
                .SingleOrDefault(b => budgetDate <= b.DateTo && budgetDate >= b.DateFrom);
        }

        public Budget GetDraftedBudget()
        {
            return UnitOfWork.Session.Query<Budget>().SingleOrDefault(x => x.IsDraft);
        }
    }
}
